* Firm organization with multiple establishments
* Appendix A: Tables A.21-A.26

clear all 
set matsize 2000
set more off

capture log close
log using log/41_cmrh-cs_replication_est.log, replace

********************************************************************************
********************************************************************************
* Use individual-level dataset
use data/CMRH_2012_p_layer-ind.dta, clear

merge m:1 betnr jahr using data/est_count_mgmt_unt.dta
drop _merge
keep if hauptbet == 0 & count_est > 1

gen w08_2 = int(w08_5 / 1000)


*table A.21: wage distribution by layer
*****************************

tabstat tentgelt, by(layer) s(n mean sd p5 p10 q p90 p95)
//	# obs.
tab layer, missing

* table A.22: Run stats without retail
tabstat tentgelt if w08_2 != 47, by(layer_rank) s(n mean sd p5 p10 q p90 p95)

********************************************************************************
********************************************************************************
* Use establishment-level dataset

use data/CMRH_2012_cs_est_layer-firm.dta if hauptbet == 0 & count_est > 1, clear

duplicates report betnr jahr

*tables A.23 and A.24: statistics by layers
******************************
table count_mgmt_est, c(n empl_est mean empl_est mean avg_wage median avg_wage)
table count_mgmt_unt, c(n empl_est mean empl_est mean avg_wage median avg_wage)

*table A.25: combinations of layers
***************************************************
tab2 count_mgmt_unt count_mgmt_est

*table A.26: fraction of firms with correct ordering
***************************************************
tabulate correctlyr count_mgmt_est, col nofreq
tabulate correctlyr count_mgmt_est [aweight=empl_est], col nofreq
//	# obs.
tabulate correctlyr count_mgmt_est
tabulate correctlyr count_mgmt_est [aweight=empl_est]
******************** end table

log close

clear all
